from openai import OpenAI

client = OpenAI(
    api_key="sk-e39b058a837f49bc80f521305d34ce44",
    base_url="https://api.deepseek.com"
)

response = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {"role": "system", "content": "你是一个函数控制助手"},
        {"role": "user", "content": "查询今天的天气"}
    ],
    functions=[
        {
            "name": "get_weather",
            "description": "查询指定城市的天气",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "城市名称"
                    }
                },
                "required": ["city"]
            }
        }
    ],
    function_call="auto"
)

print(response.choices[0].message.function_call)
print(response.choices[0].message.content)
